<?php


namespace catchAdmin\storehouse\controller;


use catchAdmin\product\model\Product;
use catchAdmin\stock\model\Pick;
use catchAdmin\stock\model\Stock;
use catchAdmin\storehouse\controller\InventoryOperationRecord;
use catchAdmin\storehouse\model\WarehouseOutSon as WarehouseOutSonModel;
use catchAdmin\storehouse\model\WarehouseOut;
use catcher\base\CatchController;
use catcher\base\CatchRequest as Request;
use catcher\CatchAuth;
use catcher\CatchResponse;
use catcher\Utils;
use think\Exception;
use think\facade\Db;

class WarehouseOutSon extends CatchController
{
    protected $warehouseOutSon;

    public function __construct(WarehouseOutSonModel $warehouseOutSon)
    {
        $this->warehouseOutSon = $warehouseOutSon;
    }

    /**
     *
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function index(CatchAuth $auth)
    {
        $user = $auth->user();
        $list = $this->warehouseOutSon->getList($user['tenant_id']);
        foreach ($list as $k => $v) {
            $list[$k]['tip'] = $k + 1;
        }
        return CatchResponse::paginate($list);
    }

    /**
     *
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function getProduct(CatchAuth $auth)
    {
        $user = $auth->user();
        $list = $this->warehouseOutSon->getAttrList($user['tenant_id']);
        return CatchResponse::success($list->toArray(), '查询成功');
    }

    /**
     *
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function create(CatchAuth $auth, Request $request)
    {
        $params = $request->param();
        $user = $auth->user();
        $params['tenant_id'] = $user['tenant_id'];
        $params['goods_name'] = $params['packing_id'][0];
        $params['goods_id'] = $params['packing_id'][2];
        $params['packing_id'] = $params['packing_id'][1];
        $params['warehouse_out_son_id'] = $user['tenant_id'] . date('YmdHis') . mt_rand(1000000, 9999999);
        $params = $this->goods_info($params);


        //检货锁定表
        $project_client = DB::name('db_warehouse_out')->where('warehouse_out_id', $request->post('warehouse_out_id'))->value('project_client');

        if (empty($packing_params = $request->post('packing_id')) || empty($packing_params[0]) || empty($packing_params[1])) {
            return CatchResponse::fail('参数错误，未指定商品或包装。');
        }

        $pick_list = (new Pick)->getListByClientGnamePid($project_client, $request->post('packing_id')[0], $request->post('packing_id')[1]);

        $pick_locking_num = array_sum(array_column($pick_list, 'number'));

        //重新计算一下，仓库好的数量
        $new_where['project_client'] = $project_client;
        $new_where['goods_name'] = $request->post('packing_id')[0];
        $new_where['packing_id'] = $request->post('packing_id')[1];

        $stock_number = DB::name('db_stock')
//            ->field('SUM(number) as number')
//            ->field('(SUM(number) - SUM(out_number)) as number')
            ->field('SUM(Good_Qty + Hold_Qty + NG_Qty) as number')
            ->where($new_where)
            ->where('status', '<>', 1)
//            ->where('Good_Qty','>',0)
            ->where('deleted_at', 0)
            ->find();
        $stock_number = (int)$stock_number['number'];

        if ($request->post('number') > $stock_number - $pick_locking_num) {
            $failStr = "可用库存不足，目标出库数量{$request->post('number')}，总可用库存：{$stock_number}";
            if (0 != $pick_locking_num) {
                $failStr .= "，包含已捡货数量：" . $pick_locking_num;
            }
            return CatchResponse::fail($failStr);
        }

        if ($params['code'] === 0) {
            return CatchResponse::fail($params['msg']);
        }

        //出库筛选
        $params['data']['conditions_warehousing_no'] = implode(',', $request->post('warehousing_select_no'));

        Db::startTrans();
        try {
            //创建
            $pk = $this->warehouseOutSon->storeBy($params['data']);

            //修改主单状态
            $warehouseOut = (new WarehouseOut)->where('warehouse_out_id', $request->post('warehouse_out_id'))->find();
            if (1 == $warehouseOut->status) {//将之前全部出库，改成部分出库
                $warehouseOut->status = 2;
                $warehouseOut->save();
            }


            Db::commit();
            return CatchResponse::success($pk);
        } catch (\Exception $exception) {
            Db::rollback();
            return CatchResponse::fail('失败' . $exception->getMessage());
        }


    }

    /**
     *
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function update(CatchAuth $auth, Request $request)
    {
        $params = $request->filterEmptyField()->param();
        $user = $auth->user();
        $params['goods_id'] = $params['goods_id'];
        //$params['goods_name'] = $params['packing_id'][0];
        $params['packing_id'] = $params['packing_id'];
        $params = $this->goods_info($params);
        if ($params['code'] === 0) {
            return CatchResponse::fail($params['msg']);
        } else {
            $project_client = DB::name('db_warehouse_out')->where('warehouse_out_id', $request->post('warehouse_out_id'))->value('project_client');

            $new_where['project_client'] = $project_client;
            $new_where['goods_id'] = $request->post('goods_id');
            $new_where['packing_id'] = $request->post('packing_id');

            $stock_number = DB::name('db_stock')
//            ->field('SUM(number) as number')
//            ->field('(SUM(number) - SUM(out_number)) as number')
                ->field('SUM(Good_Qty) as number')
                ->where($new_where)
                ->where('status', '<>', 1)
                ->where('Good_Qty', '>', 0)
                ->where('deleted_at', 0)
                ->find();
            $stock_number = (int)$stock_number['number'];

            if ($request->post('number') > $stock_number) {
                $failStr = "可用库存不足，目标出库数量{$request->post('number')}，良品可用库存：{$stock_number}";

                return CatchResponse::fail($failStr);
            }


            $id = $params['data']['id'];

            //出库筛选
            $params['data']['conditions_warehousing_no'] = implode(',', input('post.warehousing_select_no'));
            //$result = Db::table('db_warehouse_out_son')->where('id',$id)->update($params['data']);
            $result = $this->warehouseOutSon->updateBy($id, $params['data']);
            if (!empty($params['data']['PO'])) {
                Product::where('goods_id', $new_where['goods_id'])
                    ->update([
                        'serial_number' => $params['data']['PO']
                    ]);
            }
            return CatchResponse::success();
        }
    }

    /**
     *
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function delete(Request $request)
    {
        $id = $request->post('id');
        $id = is_array($id) ? $id : [$id];
        //$warehouseOutSonModel = new WarehouseOutSonModel;

        $warehouse_out_son = $this->warehouseOutSon->where('id', 'in', $id)->select()->toArray();
        foreach ($warehouse_out_son as $value) {
            if ($value['status'] != 0) {
                return CatchResponse::fail('该订单商品已出库，请确认！');
            }
            $map = [];
            $map[] = ['deleted_at', '=', 0];
            $map[] = ['warehouse_out_son_id', '=', $value['warehouse_out_son_id']];
            $if_lock = Db::table('db_pick')->where($map)->select()->toArray();
            if (!empty($if_lock)) {
                return CatchResponse::fail('该订单商品已拣货，请先清除锁定！');
            }
        }
        Db::startTrans();
        try {
            $this->warehouseOutSon->deleteBy($id);
            //Db::rollback();
            Db::commit();
        } catch (\Exception $exception) {
            Db::rollback();
            return CatchResponse::fail('删除失败');
        }

        //删除最后，判断是否订单是否全部完成
        return CatchResponse::success('', '删除成功');
    }

    public function getPalletNo(Request $request)
    {
        $goodsId = $request->post('goods_id');
        $palletNo = $request->post('pallet_no');
        $list = Db::table("db_warehousing_sn")
            ->where([
                'goods_id' => $goodsId,
                'pallet_no' => $palletNo,
                'deleted_at' => 0,
            ])->where('is_out', '<>', 1)->column('sn');
        return CatchResponse::success($list);
    }

    /**
     * 快速出库
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function fastOut(CatchAuth $auth, Request $request)
    {
        $params = $request->post();
        $user = $auth->user();
        $where = [];
        $where[] = ['stock_id', 'in', $params['stock_ids']];
        $stocks = Db::table('db_stock')->where($where)->select();
        Db::startTrans();
        try {
            //主单
            Db::table('db_warehouse_out')->where('warehouse_out_id', $params['warehouse_out_id'])->update(['status' => 1]);
            //子单
            $data = [];
            $data['warehouse_out_id'] = $params['warehouse_out_id'];
            $data['warehouse_out_son_id'] = $user['tenant_id'] . date('YmdHis') . mt_rand(1000, 9999);
            $product = Db::table('db_product')->where('goods_name', $params['goods_name'])->find();
            $data['goods_id'] = $product['goods_id'];
            $data['HSCODE'] = $product['HSCODE'];
            $data['goods_name'] = $product['goods_name'];
            $data['goods_Cname'] = $product['goods_Cname'];
            $data['goods_Ename'] = $product['goods_Ename'];
            $data['supplier_id'] = $product['supplier_id'];
            $data['supplier_name'] = Db::table('db_project')->where('project_id', $product['supplier_id'])->value('project_name');
            $data['manufacturer_id'] = $product['manufacturer_id'];
            $data['manufacturer_name'] = Db::table('db_project')->where('project_id', $product['manufacturer_id'])->value('project_name');
            $data['packing_id'] = $params['packing_id'];
            $data['p_barcode'] = $params['packing_id'];
            $packing = Db::table('db_packing')->where('packing_id', $params['packing_id'])->find();
            $data['packing_num'] = $packing['packing_num'];
            $data['unit_name'] = $packing['unit_name'];
            $data['number'] = $params['total_num'];
            $data['box_number'] = $params['total_box'];
            $data['tray_number'] = count($params['stock_ids']);
            $map = [];
            $map['project_client'] = Db::table('db_warehouse_out')->where('warehouse_out_id', $params['warehouse_out_id'])->value('project_client');
            $map['goods_name'] = $params['goods_name'];
            $map['packing_id'] = $params['packing_id'];
            $stock_number = DB::name('db_stock')
                ->field('SUM(number) as number')
                ->where($map)
                ->where('deleted_at', 0)
                ->find();
            $data['stock_number'] = $stock_number['number'];
            $data['pick_number'] = $params['total_num'];
            $data['status'] = 1;
            $data['out_number'] = $params['total_num'];
            $data['tenant_id'] = $user['tenant_id'];
            $data['creator_id'] = $user['id'];
            $data['created_at'] = time();
            Db::table('db_warehouse_out_son')->insert($data);
            foreach ($stocks as $k => $v) {
                //pick stock tray
                //stock
                Db::table('db_stock')->where('stock_id', $v['stock_id'])->update(['status' => 1, 'out_number' => $v['Good_Qty'], 'Good_Qty' => 0]);
                //pick
                $arr = [];
                $arr['warehouse_out_id'] = $params['warehouse_out_id'];
                $arr['warehouse_out_son_id'] = $data['warehouse_out_son_id'];
                $arr['pick_id'] = date('YmdHis') . mt_rand(1000, 9999);
                $arr['tray_id'] = $v['tray_id'];
                $arr['number'] = $v['Good_Qty'];
                $arr['status'] = 1;
                $arr['auth_id'] = $user['id'];
                $arr['creator_id'] = $user['creator_id'];
                $arr['created_at'] = time();
                $arr['tenant_id'] = $user['tenant_id'];
                Db::table('db_pick')->insert($arr);
                //tray
                $arr = [];
                $arr['warehousing_id'] = $params['warehouse_out_id'];
                $arr['warehousing_son_id'] = $data['warehouse_out_son_id'];
                $arr['tray_id'] = $v['tray_id'];
                $arr['config_id'] = $v['config_id'];
                $arr['number'] = $v['number'];
                $arr['box_number'] = $v['box_number'];
                $arr['created_at'] = time();
                $arr['updated_at'] = time();
                $arr['status'] = 3;
                $arr['goods_status'] = 'Good';
                $arr['creator_id'] = $user['id'];
                $arr['tenant_id'] = $user['tenant_id'];
                $arr['type'] = 1;
                $arr['batch_number'] = $v['batch_number'];
                Db::table('db_tray')->insert($arr);
            }
            Db::commit();
            return CatchResponse::success('', '出库成功');
        } catch (\Exception $exception) {
            Db::rollback();
            return CatchResponse::fail('出库失败');
        }
    }

    /**
     * 一键出库
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function wholeOut(CatchAuth $auth, Request $request)
    {
        $params = $request->post();
        $user = $auth->user();
        $where = [];
        if (empty($params['warehouse_out_son_id'])) {
            $map = [];
            $map[] = ['warehouse_out_id', '=', $params['warehouse_out_id']];
            $map[] = ['deleted_at', '=', 0];
            $params['warehouse_out_son_id'] = Db::table('db_warehouse_out_son')->where($map)->column('warehouse_out_son_id');
        }
        //$where[] = ['warehouse_out_son_id','in',$params['warehouse_out_son_id']];
        $map = [];
        $map[] = ['warehouse_out_id', '=', $params['warehouse_out_id']];
        $map[] = ['deleted_at', '=', 0];
        $map[] = ['id', 'in', $params['warehouse_out_son_id']];
        $warehouse_out_son_ids = Db::table('db_warehouse_out_son')->where($map)->column('warehouse_out_son_id');
        $where[] = ['warehouse_out_son_id', 'in', $warehouse_out_son_ids];
        $where[] = ['deleted_at', '=', 0];
        $where[] = ['status', '=', 0];
        $pick = Db::table('db_pick')->where($where)->select()->toArray();
        if (empty($pick)) {
            return CatchResponse::fail('请先拣货！！！');
        }

        //出库数量判断
        $warehouse_out_son_arr = Db::table('db_warehouse_out_son')->field('number,pick_number')->where('warehouse_out_son_id', 'in', $params['warehouse_out_son_id'])->select()->toArray();

        foreach ($warehouse_out_son_arr as $value) {
            if ($value['number'] != $value['pick_number']) {
                return CatchResponse::fail('出库失败，出库明细单要求出库数量和捡货数量不一致');
            }
        }

        $insert_tray_data = [];

        Db::startTrans();
        try {

            foreach ($pick as $key => $value) {

                $stock_where = [];
                $stock_where[] = ['tray_id', '=', $value['tray_id']];
                //箱号
                if (empty($value['box_id'])) {
                    $stock_where[] = ['box_id', '=', 0];
                } else {
                    $stock_where[] = ['box_id', '=', $value['box_id']];
                }
                //片号
                if (empty($value['slice_id'])) {
                    $stock_where[] = ['slice_id', '=', 0];
                } else {
                    $stock_where[] = ['slice_id', '=', $value['slice_id']];
                }
                $stock_pick = (new Stock)->where($stock_where)->find();

                $stock_save_data = [];
                $stock_save_data['out_number'] = $stock_pick->out_number + $value['number'];//出库数量

                //判断出库的类型 Good Hold Ng
                if ($stock_pick->Good_Qty > 0) {//Good
                    $stock_save_data['Good_Qty'] = $stock_pick->Good_Qty - $value['number'];//好的数量
                    if ($stock_save_data['Good_Qty'] < 0) {
                        throw new Exception('网络错误，请稍后重试');
                    }
                    //库存状态
                    $stock_save_data['status'] = $stock_save_data['Good_Qty'] == 0 ? 1 : 2;
                } elseif ($stock_pick->Hold_Qty > 0) {
                    $stock_save_data['Hold_Qty'] = $stock_pick->Hold_Qty - $value['number'];//hold数量
                    if ($stock_save_data['Hold_Qty'] < 0) {
                        throw new Exception('网络错误，请稍后重试');
                    }
                    //库存状态
                    $stock_save_data['status'] = $stock_save_data['Hold_Qty'] == 0 ? 1 : 2;
                } elseif ($stock_pick->NG_Qty > 0) {
                    $stock_save_data['NG_Qty'] = $stock_pick->NG_Qty - $value['number'];//ng数量
                    if ($stock_save_data['NG_Qty'] < 0) {
                        throw new Exception('网络错误，请稍后重试');
                    }
                    //库存状态
                    $stock_save_data['status'] = $stock_save_data['NG_Qty'] == 0 ? 1 : 2;
                }

//                if(empty($value['box_id']) && empty($value['slice_id'])){//托库存
//                    if(0 == $stock_save_data['Good_Qty'] ){//代表出完
//                        $stock_save_data['status'] = 1;//全部出库
//                    }else{
//                        $stock_save_data['status'] = 2;//部分出库
//                    }
//                }

                //托盘数据
                $insert_tray_data_temp = [];

                $insert_tray_data_temp['batch_number'] = $stock_pick->batch_number;
                $insert_tray_data_temp['type'] = 1;
                $insert_tray_data_temp['warehousing_id'] = $value['warehouse_out_id'];
                $insert_tray_data_temp['warehousing_son_id'] = $value['warehouse_out_son_id'];
                $insert_tray_data_temp['tenant_id'] = $user['tenant_id'];
                $insert_tray_data_temp['creator_id'] = $user['id'];
                $insert_tray_data_temp['goods_status'] = 'Good';
                $insert_tray_data_temp['status'] = 3;
                $insert_tray_data_temp['created_at'] = time();
                $insert_tray_data_temp['updated_at'] = time();
                $insert_tray_data_temp['number'] = $value['number'];
                $insert_tray_data_temp['box_number'] = ceil($value['number'] / $stock_pick->packing_num);
                $insert_tray_data_temp['tray_id'] = $value['tray_id'];
                $insert_tray_data_temp['config_id'] = $stock_pick->config_id;

                //修改库存表数据
                $stock_pick->save($stock_save_data);

                //托盘数据
                $insert_tray_data[] = $insert_tray_data_temp;

                //出库明细表修改
                //出库明细表修改
                DB::name('db_warehouse_out_son')->where('warehouse_out_son_id', $value['warehouse_out_son_id'])->inc('out_number', $value['number'])->update();

                //添加库存操作记录--start
                $inventoryOperationRecordModel = new \catchAdmin\storehouse\model\InventoryOperationRecord();

                $recordMergeData = array_merge($value, [
                    'warehousing_id' => $stock_pick['warehousing_id'],
                    'warehousing_son_id' => $stock_pick['warehousing_son_id']
                ]);
                $recordResult = (new InventoryOperationRecord($inventoryOperationRecordModel))->write(InventoryOperationRecord::ORDER_TYPE_CK, $value['warehouse_out_son_id'], $recordMergeData);
                if (!$recordResult) {
                    Db::rollback();
                    throw new Exception('[出库]库存操作记录创建失败');
                }
                //添加库存操作记录--end
            }

            //插入托盘表
            Db::table('db_tray')->insertAll($insert_tray_data);

            //出库明细表状态
            $info = DB::name('db_warehouse_out_son')
                ->field('id,number,out_number,warehouse_out_id')
                ->whereIn('warehouse_out_son_id', $warehouse_out_son_ids)
                ->select()
                ->toArray();

            foreach ($info as $key => $value) {
                if ($value['number'] === $value['out_number']) {
                    //全部出库
                    $status = 1;
                } elseif (($value['out_number'] !== 0) && ($value['number'] > $value['out_number'])) {
                    //部分出库
                    $status = 2;
                }

                $a = DB::name('db_warehouse_out_son')->where('id', $value['id'])->update(['status' => $status, 'updated_at' => time()]);

            }

//            //出库表状态
//            $map=[];
//            $map[]=['warehouse_out_id','in',$params['warehouse_out_id']];
//            $map[]=['deleted_at','=',0];
//            $out = DB::name('db_warehouse_out_son')->where($map)->column('status');


//            $out_son_status = array_unique($out);//出库子订单，状态
//            if(in_array(0,$out_son_status) || in_array(2,$out_son_status)){//部分出库
//                $status = 2;
//            }else{
//                $status = 1;
//            }

            //入库主单更改状态------start
            $warehouse_out_son_all_number = Db::table('db_warehouse_out_son')
                ->where('warehouse_out_id', $params['warehouse_out_id'])
                ->where('deleted_at', 0)
                ->where('status', 1)
                ->sum('out_number');

            $warehouse_out_number = Db::table('db_warehouse_out')->where('warehouse_out_id', $params['warehouse_out_id'])->value('goods_number');

            if ($warehouse_out_son_all_number == $warehouse_out_number) {
                $data = [];
                $data['actual_number'] = $warehouse_out_son_all_number;
                $data['status'] = 1;
                $data['updated_at'] = time();
                Db::table('db_warehouse_out')->where('warehouse_out_id', $params['warehouse_out_id'])->update($data);
            } else if ($warehouse_out_son_all_number > 0 && $warehouse_out_son_all_number < $warehouse_out_number) {
                $data = [];
                $data['actual_number'] = $warehouse_out_son_all_number;
                $data['status'] = 2;
                $data['updated_at'] = time();
                Db::table('db_warehouse_out')->where('warehouse_out_id', $params['warehouse_out_id'])->update($data);
            } else {
                throw new Exception('出库数量错误，请检查捡货单是否正确');
            }
            //入库主单更改状态------end

            //拣货表
            DB::name('db_pick')->where($where)->update(['status' => 1, 'updated_at' => time(), 'auth_id' => $request->user()->id]);
            $snArr = array_column($pick,'sn');
            //throw new Exception(json_encode($snArr));
            Db::table('db_warehousing_sn')
                ->whereIn('sn',$snArr)->update([
                'is_out'=>1,
                'updated_at'=>time()
            ]);
            Db::commit();
            return CatchResponse::success('', 'success');
        } catch (\Exception $exception) {
            Db::rollback();
            return CatchResponse::fail($exception->getMessage());
        }


    }

    /**
     * 商品信息
     * @return array
     */
    public function goods_info($params)
    {
        //统计委托方在仓库里商品的总量
        $where1['warehouse_out_id'] = $params['warehouse_out_id'];
        $project_client = DB::name('db_warehouse_out')->where($where1)->value('project_client');

        $where['project_client'] = $project_client;
        $where['goods_id'] = $params['goods_id'];
        $where['packing_id'] = $params['packing_id'];
        $stock_number = DB::name('db_stock')
            ->field('SUM(number) as number')
            ->where($where)
            ->where('deleted_at', 0)
            ->find();

        $params['stock_number'] = (int)$stock_number['number'];

        //商品
        $info = DB::name('db_product')
            ->field('barcode,goods_id,goods_name,goods_Ename,goods_Cname,supplier_id,manufacturer_id,HSCODE')
            ->where('goods_id', $params['goods_id'])
            ->where('deleted_at', 0)
            ->find();
        if (empty($info)) {
            return array('code' => 0, 'msg' => '商品信息不存在');
        }

        $params['HSCODE'] = $info['HSCODE'];
        $params['goods_id'] = $info['goods_id'];
        $params['goods_name'] = $info['goods_name'];
        $params['goods_Ename'] = $info['goods_Ename'];
        $params['goods_Cname'] = $info['goods_Cname'];
        $params['supplier_id'] = $info['supplier_id'];
        $params['manufacturer_id'] = $info['manufacturer_id'];

        if (!empty($params['supplier_id'])) {
            if (strlen($params['supplier_id']) < 10) {//新的供应商来自用户表
                $params['supplier_name'] = Db::table('db_provider')->where('id', $params['supplier_id'])->value('account_name');
            } else {
                $params['supplier_name'] = DB::name('db_supplier')
                    ->where('supplier_id', $info['supplier_id'])
                    ->where('deleted_at', 0)
                    ->value('supplier_name');
                if (empty($params['supplier_name'])) {
                    return array('code' => 0, 'msg' => '商品供应商不存在');
                }
            }
        }

        if (!empty($params['manufacturer_id'])) {
            if (strlen($params['manufacturer_id']) < 10) {//新的供应商来自用户表
                $params['supplier_name'] = Db::table('db_provider')->where('id', $params['manufacturer_id'])->value('account_name');
            } else {
                $params['manufacturer_name'] = DB::name('db_manufacturer')
                    ->where('manufacturer_id', $info['manufacturer_id'])
                    ->where('deleted_at', 0)
                    ->value('manufacturer_name');
                if (empty($params['manufacturer_name'])) {
                    return array('code' => 0, 'msg' => '商品制造商不存在');
                }
            }
        }

        //包装
        $packing = DB::name('db_packing')
            ->field('packing_num,unit_name,packing_id')
            ->where('packing_id', $params['packing_id'])
            ->where('deleted_at', 0)
            ->find();

        if (empty($packing)) {
            return array('code' => 0, 'msg' => '商品包装单位不存在');
        }
        $params['p_barcode'] = $packing['packing_id'];
        $params['packing_num'] = $packing['packing_num'];
        $params['unit_name'] = $packing['unit_name'];

        return array('code' => 1, 'msg' => '', 'data' => $params);
    }
}